#ifndef AVALON_CONNECTION_HPP
#define AVALON_CONNECTION_HPP
#include <boost/signals2.hpp>
#include "Avalon/IO/IO.hpp"

namespace Avalon {
namespace IO {

  /*! \class Connection
   *  \brief Interface for a connection based IO resource.
   *  \author Kamal Mansouri <kranar@hotmail.com>
   */
  class Connection {
    public:

      //! Signals that the connection closed.
      /*!
        \brief Once signaled, all existing slots are disconnected.
      */
      typedef boost::signals2::signal<void ()> ClosedSignal;

      virtual ~Connection();

      //! Returns <code>true</code> iff the connection is open.
      virtual bool IsConnected() = 0;

      //! Closes the existing connection.
      virtual void Close() = 0;

      //! Connects to the ClosedSignal.
      /*!
        \param slot The slot to connect.
        \return The <i>slot</i>'s connection to the signal.
      */
      virtual boost::signals2::connection ConnectClosedSignal(
        const ClosedSignal::slot_type& slot) = 0;

      //! Connects to the ClosedSignal.
      /*!
        \param slot The slot to connect.
        \param isConnected [out] <code>true</code> iff the connection is open.
        \return The <i>slot</i>'s connection to the signal.
      */
      virtual boost::signals2::connection ConnectClosedSignal(
        const ClosedSignal::slot_type& slot, bool* isConnected) = 0;
  };
}
}

#endif // AVALON_CONNECTION_HPP
